package com.varian.tool.tree;

import cn.hutool.core.comparator.CompareUtil;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.List;

/**
 * @author ben
 * @since 2024/7/4
 */
public interface INode<T> extends Comparable<INode<T>>{

    Long getId();

    Long getParentId();

    Comparable<?> weight();

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    List<T> getChildren();

    T setChildren(List<T> children);

    @SuppressWarnings({"unchecked", "rawtypes", "NullableProblems"})
    @Override
    default int compareTo(INode node) {
        if(null == node){
            return 1;
        }
        final Comparable weight = this.weight();
        final Comparable weightOther = node.weight();
        return CompareUtil.compare(weight, weightOther);
    }
}
